package com.migration.model.migration.scripts;

import com.migration.model.migration.AbstractMigrationScript;

/**
 * 风险等级矩阵表(risk_matrix_result)迁移脚本
 */
public class A017_RiskMatrixResultMigrationScript extends AbstractMigrationScript {

    /**
     * 构造函数，初始化迁移配置
     */
    public A017_RiskMatrixResultMigrationScript() {
        super(
            "risk_matrix_result",
            "风险等级矩阵数据迁移",
            "ra_evaluation_matrix",
            "risk_matrix_result",
            17
        );
    }

    /**
     * 生成迁移数据的SQL
     *
     * @return 迁移数据的SQL
     */
    @Override
    protected String generateMigrationSql() {
        return "INSERT INTO risk_matrix_result (\n" +
                "    id,\n" +
                "    tenant_id,\n" +
                "    likelihood_id,\n" +
                "    severity_id,\n" +
                "    level_id,\n" +
                "    create_time,\n" +
                "    update_time,\n" +
                "    create_by,\n" +
                "    update_by,\n" +
                "    is_del\n" +
                ")\n" +
                "SELECT\n" +
                "    em.id,\n" +
                "    1 AS tenant_id,\n" +
                "    em.possible_grade_id AS likelihood_id,\n" +
                "    em.severity_grade_id AS severity_id,\n" +
                "    em.risk_grade_id AS level_id,\n" +
                "    DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s') AS create_time,\n" +
                "    DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s') AS update_time,\n" +
                "    1,\n" +
                "    1,\n" +
                "    0 AS is_del\n" +
                "FROM risk_lunnan_test.ra_evaluation_matrix em\n" +
                "INNER JOIN risk_lunnan_test.ra_risk_grade rg on rg.id = em.risk_grade_id and rg.tenant_id = 24\n;";
    }

}
